package com.core.web.struts2.taglib;

import org.apache.struts2.views.jsp.*;

import javax.servlet.jsp.*;

/**
 * password JSP 标签
 * 
 * 
 */
public class PasswordTag extends CommonTag {

	@Override
	public int doStartTag() throws JspException {
		return SKIP_BODY;
	}

	@Override
	public int doEndTag() throws javax.servlet.jsp.JspException {
		try {
			pageContext.getOut().print(getHtml());
		} catch (Exception e) {
			throw new JspException(e);
		}
		return EVAL_BODY_INCLUDE;
	}

	private String getHtml() {
		StringBuffer ret = new StringBuffer();
		Object stackObject = TagUtils.getStack(this.pageContext)
				.findValue(name);
		String inputValue = "";

		if (getValue() != null && !getValue().equals("")) {
			inputValue = getValue();
		}
		if (stackObject!=null && !stackObject.equals("")) {
			inputValue = stackObject.toString();
		}

		ret.append("<input type=\"password\" ").append(super.getCommonHtml())
				.append(" value=\"").append(inputValue).append("\" >");
		return ret.toString();
	}
}
